import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yyshort/common/model/goods_model.dart';

class TicketComponent extends StatefulWidget {
  final GoodsModel goods;
  final VoidCallback onTap;

  const TicketComponent({super.key, required this.goods, required this.onTap});

  @override
  State<TicketComponent> createState() => _TicketComponentState();
}

class _TicketComponentState extends State<TicketComponent> {
  // 点击状态控制变量
  bool _isPressed = false;

  @override
  Widget build(BuildContext context) {
    final total = (widget.goods.giftGoodCoin ?? 0);

    return Container(
      // width: 150.w,
      // height: 160.h,
      // color: Colors.orange,
      // 点击时显示淡淡的金色阴影
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6),
        boxShadow: [
          if (_isPressed)
            BoxShadow(
              // ignore: deprecated_member_use
              color: const Color(0xFFFEB42C).withOpacity(0.3),
              blurRadius: 6,
              spreadRadius: 0,
              offset: const Offset(0, 2),
            )
          else
            BoxShadow(color: Colors.transparent),
        ],
      ),
      child: InkWell(
        onTap: widget.onTap,
        // 点击状态回调
        onTapDown: (_) => setState(() => _isPressed = true),
        onTapUp: (_) => setState(() => _isPressed = false),
        onTapCancel: () => setState(() => _isPressed = false),
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        child: Container(
          // 点击时显示金色边框
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6),
            border: Border.all(
              color: _isPressed ? const Color(0xFFFEB42C) : Colors.transparent,
              width: 1.2,
            ),
          ),
          clipBehavior: Clip.antiAlias,
          child: Column(
            children: [
              Expanded(
                child: Container(
                  // width: double.infinity,
                  // 背景色从深灰提亮为浅灰
                  decoration: BoxDecoration(
                    color: _isPressed
                        // ignore: deprecated_member_use
                        ? const Color(0xFF35343A).withOpacity(0.8)
                        // ignore: deprecated_member_use
                        : const Color(0xFF2D2C31).withOpacity(0.8),
                    borderRadius: const BorderRadius.vertical(
                      top: Radius.circular(6),
                    ),
                  ),
                  child: Stack(
                    children: [
                      if (widget.goods.rate != null && widget.goods.rate! > 0)
                        Positioned(
                          top: 0,
                          right: 0,
                          child: Container(
                            // width: 50.w,
                            // height: 22.h,
                            decoration: BoxDecoration(
                              gradient: const LinearGradient(
                                begin: Alignment.topLeft,
                                end: Alignment.bottomRight,
                                colors: [Color(0xFFF7BE76), Color(0xFFFFE9B8)],
                                stops: [0.0, 1.0],
                                transform: GradientRotation(
                                  116 * 3.1415926535 / 180,
                                ),
                              ),
                              borderRadius: const BorderRadius.only(
                                bottomLeft: Radius.circular(10),
                              ),
                            ),
                            child: Center(
                              child: Text(
                                '+${widget.goods.rate}%',
                                style: const TextStyle(
                                  fontFamily: "PingFangSC",
                                  fontSize: 14,
                                  color: Colors.black,
                                ),
                              ),
                            ),
                          ),
                        ),

                      Column(
                        children: [
                          Expanded(child: SizedBox()),

                          Padding(
                            padding: const EdgeInsets.only(top: 13),
                            child: Text(
                              widget.goods.goodCoin.toString(),
                              style: TextStyle(
                                fontFamily: "PingFangSC",
                                fontSize: 36,
                                // 币数量文字从半透明白变为纯白色
                                color: _isPressed
                                    ? Colors.white
                                    : Colors.white70,
                              ),
                            ),
                          ),
                          Expanded(child: SizedBox()),
                          // SizedBox(height: 10.h,),
                          Container(
                            padding: const EdgeInsets.symmetric(
                              horizontal: 8,
                              vertical: 4,
                            ),
                            decoration: BoxDecoration(
                              // ignore: deprecated_member_use
                              color: const Color(0xFFFEB42C).withOpacity(0.5),
                              borderRadius: BorderRadius.circular(12),
                            ),

                            child: Text(
                              "+$total",
                              style: const TextStyle(
                                fontFamily: "PingFangSC",
                                fontSize: 18,
                                color: Color(0xFFFEB42C),
                              ),
                            ),
                          ),
                          Expanded(child: SizedBox()),

                          Align(
                            alignment: Alignment.bottomCenter,
                            child: Padding(
                              padding: const EdgeInsets.only(bottom: 8),
                              child: Text(
                                "币".tr,
                                style: TextStyle(
                                  fontFamily: "PingFangSC",
                                  fontSize: 14,
                                  color: Colors.white70,
                                ),
                              ),
                            ),
                          ),
                          Expanded(child: SizedBox()),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                width: double.infinity,
                height: 30.h,
                // 底部背景色从深灰提亮为浅灰
                decoration: BoxDecoration(
                  color: _isPressed
                      // ignore: deprecated_member_use
                      ? const Color(0xFF403E47).withOpacity(0.8)
                      // ignore: deprecated_member_use
                      : const Color(0xFF38363F).withOpacity(0.8),
                  borderRadius: const BorderRadius.vertical(
                    bottom: Radius.circular(6),
                  ),
                ),
                child: Center(
                  child: Text(
                    "\$ ${widget.goods.goodUsPrice?.toStringAsFixed(2) ?? ''}",
                    style: TextStyle(
                      fontFamily: "PingFangSC",
                      fontSize: 18,
                      // 价格文字从半透明白变为纯白色
                      color: _isPressed ? Colors.white : Colors.white70,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
